Use std::prev ove -1ing the iterator
authorClaudio Cambra <claudio.cambra@nextcloud.com>
Thu, 28 Nov 2024 09:58:23 +0000 (17:58 +0800)
committerMatthieu Gallien <matthieu.gallien@nextcloud.com>
Fri, 20 Dec 2024 15:26:57 +0000 (16:26 +0100)
Signed-off-by: Claudio Cambra <claudio.cambra@nextcloud.com>
Use std::prev for it rather than -1 in Syncengine

Signed-off-by: Claudio Cambra <claudio.cambra@nextcloud.com>
src/libsync/discovery.cpp
src/libsync/syncengine.cpp

index 4d8f57dfbf3a3c05e748727745ac021949842f19..927a248da67b0991b926bcd409f1ba8e9668fd24 100644 (file)
@@ -1824,7 +1824,7 @@ bool ProcessDirectoryJob::checkPermissions(const OCC::SyncFileItemPtr &item)
         QString fileSlash = item->_file + '/';
         auto forbiddenIt = _discoveryData->_forbiddenDeletes.upperBound(fileSlash);
         if (forbiddenIt != _discoveryData->_forbiddenDeletes.begin())
-            forbiddenIt -= 1;
+            forbiddenIt = std::prev(forbiddenIt);
         if (forbiddenIt != _discoveryData->_forbiddenDeletes.end()
             && fileSlash.startsWith(forbiddenIt.key())) {
             item->_instruction = CSYNC_INSTRUCTION_NEW;
index f691ce09da3a899ba8a0a97d0bfbc2515bf20ad4..368d0f8c899bdc6ae928b0523513f8b2a9e77352 100644 (file)
@@ -1205,8 +1205,8 @@ bool SyncEngine::wasFileTouched(const QString &fn) const
     // Start from the end (most recent) and look for our path. Check the time just in case.
     auto begin = _touchedFiles.constBegin();
     for (auto it = _touchedFiles.constEnd(); it != begin; --it) {
-        if ((it-1).value() == fn)
-            return std::chrono::milliseconds((it-1).key().elapsed()) <= s_touchedFilesMaxAgeMs;
+        if (const auto prevIt = std::prev(it); prevIt.value() == fn)
+            return std::chrono::milliseconds(prevIt.key().elapsed()) <= s_touchedFilesMaxAgeMs;
     }
     return false;
 }